<?php
class My_Login {
	public function login($username, $password) {
		
		$db = Zend_Registry::get ( 'db' );
		$authAdapter = new Zend_Auth_Adapter_DbTable ( $db );
		$authAdapter->setTableName ( 'bc_users' );
		$authAdapter->setIdentityColumn ( 'username' );
		$authAdapter->setCredentialColumn ( 'password' );
		$authAdapter->setCredentialTreatment ( 'MD5(?)' );
		
		// Set the input credential values to authenticate against
		$authAdapter->setIdentity ( $username );
		$authAdapter->setCredential ( $password );
		
		// do the authentication
		$auth = Zend_Auth::getInstance ();
		$result = $auth->authenticate ( $authAdapter );
		//				die ();
		if ($result->isValid ()) {
			// success : store database row to auth's storage system
			// (not the password though!)
			$data = $authAdapter->getResultRowObject ( null, 'password' );
			$auth->getStorage ()->write ( $data );
			//					echo $data;
			//					var_dump($auth);
			//			echo $result->getIdentity () ;
			$identity = $result->getIdentity ();
			return $data;
		} else {
			return false;
		}
	}
}
?>